var echartsBuild = {
	//折线
	echartsLine:function(xData,yName,seriesName,seriesData){
		return {
			grid:{
				top:30,
				// width:240,
				height:80,
				left:50
			},
		    tooltip: {
		      trigger: 'axis',
		      axisPointer: {
		        type: 'cross',
		        crossStyle: {
		          color: '#999'
		        }
		      }
		    },
		    xAxis: [
		      {
		        type: 'category',
		        data: xData,
		        axisPointer: {
		          type: 'shadow'
		        },
		        axisLabel:{
		            color:"rgba(255,255,255,.6)",
		            fontSize: '12'
		        },
		        axisLine:{
		            show: false
		        }
		      }
		    ],
		    yAxis: [
		       {
		        type: 'value',
		        name: yName,
		        min: 0,
		        max: 1400,
		        interval: 200,
				nameTextStyle:{
					color:"#ffffff",
					fontSize:"14"
				},
		        axisLabel:{
		            color:"rgba(255,255,255,.6)",
		            fontSize: '12'
		        },
		        axisLine:{
		            lineStyle:{
		                color:"rgba(255,255,255,.1)",
		            }
		        },
		        splitLine:{
		            lineStyle:{
		                color:"rgba(255,255,255,.1)",
		            }
		        }
		      }
		    ],
		    series: [
		      {
		        name: seriesName,
		        type: 'line',
		        barWidth:"35%",
				areaStyle:{},
		        itemStyle:{
		            normal:{
		                barBorderRadius: 5,
		                color: new echarts.graphic.LinearGradient(0,0,0,1,[{offset: 1,color: '#33cabb'},{offset: 0,color: '#3EACE5'}])
		                // color:"#2f89cf",
		            },
		        },
		        data: seriesData
		      }
		    ]
		};
	},
	//横向柱状
	echartsColumnar:function(titleName,yData,seriesData,grid) {
		return {
		  title: {
			text: titleName,
			textStyle:{
				color:"#ffffff",
				fontSize:"14",
			}
		  },
		  tooltip: {
			trigger: 'axis',
			axisPointer: {
			  type: 'shadow'
			}
		  },
		  legend: {},
		  grid: grid,
		  xAxis: {
			show:false,
			type: 'value',
			boundaryGap: [0, 0.01]
		  },
		  yAxis: {
			type: 'category',
			axisLabel:{
				color:"#00aaff"
			},
			data: yData
		  },
		  series: [
			{
			  name: '',
			  type: 'bar',
			  showBackground:true,
			  itemStyle:{
				  color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
							{ offset: 0, color: '#83bff6' },
							{ offset: 0.5, color: '#188df0' },
							{ offset: 1, color: '#188df0' }
						  ])
			  },
			  data: seriesData,
			  label:{
				  show:true,
				  position:"right"
			  }
			}
		  ]
		};
	},
	//饼图
	echartsPie:function(parmas) {
		return {
		  title: [
		    {
		      subtext: parmas[0].titleName,
		      left: '16.67%',
		      top: '85%',
		      textAlign: 'center',
			  subtextStyle:{
				  color:"#fff"
			  }
		    },
		    {
		      subtext: parmas[1].titleName,
		      left: '50%',
		      top: '85%',
		      textAlign: 'center',
			  subtextStyle:{
				  color:"#fff"
			  }
		    },
		    {
		      subtext: parmas[2].titleName,
		      left: '83.33%',
		      top: '85%',
		      textAlign: 'center',
			  subtextStyle:{
				  color:"#fff"
			  }
		    }
		  ],
		  series: [
		    {
		      type: 'pie',
		      radius: '80%',
		      center: ['50%', '50%'],
		      data: parmas[0].data,
		      label: {
		        position: 'inside',
		        alignTo: 'none',
		        bleedMargin: 5,
				formatter: '{name|{b} |} {num|{@[0]} {@[1]}}',
				rich: {
				  name:{
					color: '#1e9fff',
					fontSize: 12,
					lineHeight:10
				  },
				  num: {
					fontSize: 10,
					color: '#fff',
					lineHeight:10
				  }
				}
		      },
		      left: 0,
		      right: '66.6667%',
		      top: 0,
		      bottom: 0
		    },
		    {
		      type: 'pie',
		      radius: '80%',
		      center: ['50%', '50%'],
		      data: parmas[1].data,
		      label: {
		        position: 'inside',
		        alignTo: 'labelLine',
		        bleedMargin: 5,
				formatter: '{name|{b} |} {num|{@[0]} {@[1]}}',
				rich: {
				  name:{
					color: '#1e9fff',
					fontSize: 12,
					lineHeight:10
				  },
				  num: {
					fontSize: 10,
					color: '#fff',
					lineHeight:10
				  }
				}
		      },
		      left: '33.3333%',
		      right: '33.3333%',
		      top: 0,
		      bottom: 0
		    },
		    {
		      type: 'pie',
		      radius: '80%',
		      center: ['50%', '50%'],
		      data: parmas[2].data,
		      label: {
		        position: 'inside',
		        alignTo: 'edge',
		        margin: 20,
				formatter: '{name|{b} |} {num|{@[0]} {@[1]}}',
				rich: {
				  name:{
					color: '#1e9fff',
					fontSize: 12,
					lineHeight:10
				  },
				  num: {
					fontSize: 10,
					color: '#fff',
					lineHeight:10
				  }
				}
		      },
		      left: '66.6667%',
		      right: 0,
		      top: 0,
		      bottom: 0
		    }
		  ]
		};
	},
	//列表
	listTop:function(tableId,listData) {
		var html = "";
		$.each(listData,function(i,d){
			html += "<tr>";
			$.each(d,function(ii,dd) {
				html += "<td>"+dd+"</td>";
			});
			html += "</tr>";
		});
		$("tbody",tableId).html(html);
	},
	//地图
	initMap:function(mapData,data,flowData,stationData) {
		var MapChart = echarts.init(mapData);
		$.get('json/zhejiang.json',function(geoMap) {
		  echarts.registerMap('zhejiang',geoMap);
		  var geoCoordMap = {
		    "杭州市": [120.153576, 30.287459],
		    "湖州市": [120.102398, 30.867198],
		    "嘉兴市": [120.750865, 30.762653],
		    "宁波市": [121.549792, 29.868388],
		    "舟山市": [122.106863, 30.016028],
		    "丽水市": [119.921786, 28.451993],
		    "金华市": [119.649506, 29.089524],
		    "台州市": [121.428599, 28.661378],
		    "绍兴市": [120.582112, 29.997117],
		    "温州市": [120.672111, 28.000575],
		    "衢州市": [118.87263, 28.941708]
		  };
		    var max = 480, min = 9; // todo 
		    var maxSize4Pin = 100, minSize4Pin = 20;
		
		  var convertData = function (data) {
		    var res = [];
		    for (var i = 0; i < data.length; i++) {
		        var geoCoord = geoCoordMap[data[i].name];
		        if (geoCoord) {
		            res.push({
		                name: data[i].name,
		                value: geoCoord.concat(data[i].value)
		            });
		        }
		    }
		    return res;
		};
		
		
		option = {
			geo: {
				show: true,
				type:'map',
				map: 'zhejiang',
				zoom:1.4,
				label: {
					normal: {
						show: false,
					},
					emphasis: {
						show: false,
					}
				},
				roam: true,
				itemStyle: {
					normal: {
						areaColor: '#142957',
						borderColor: '#0692a4',
					},
					emphasis: {
						areaColor: '#0b1c2d',
					}
				}
			},
			series : [
			{
				name: 'credit_pm2.5',
				type: 'scatter',
				coordinateSystem: 'geo',
				data: convertData(data),
				symbolSize:function(value) {
					return 1;
				},
				label: {
					normal: {
						formatter: '{b}',
						position: 'right',
						show: true
					},
				  emphasis: {
					  show: true
				  }
				},
				itemStyle: {
					normal: {
						color: '#D4EEFF'
					}
				}
			},
			//弹出tip
			{
				name: '点',
				type: 'scatter',
				coordinateSystem: 'geo',
				symbol: 'rect',
				symbolSize: function () {
					return 1;
				},
				label: {
					normal: {
						show: true,
						formatter: '{b}\n 站点总量：{@[2]}',
						lineHeight: 20,
					   backgroundColor:'rgba(255,255,255,.9)',
					   borderColor:'#80cffd',
					   borderWidth:'1',
					   padding:[5,10,4],
					   color:'#000000',
					   fontSize: 14,
					   fontWeight:'normal',
					}
				},
				zlevel: 6,
				data: convertData(data),
			}
		]
		};
		
		MapChart.setOption(option);
			
		MapChart.on("click",function(params){//地图上点击事件,省级可以点击，市级不能
			if(params.name.indexOf("绍兴市") != -1) {
				MapChart.clear();
				make_city(params.name.substr(0,2),MapChart);
				//执行数据置入
				// stationData
				echartsBuild.initShaoXingData();
				$("#cityStationData").show();
				$(".backButton").show();
				$(".process-data").hide();
				$("#proStationData").hide();
				//设置参数标记
				$("#levelgov").val(2);
				//修改标题
				var title = $("#titles").text();
				$("title").html(title.replace("{}","绍兴"));
				$("header h1").html(title.replace("{}","绍兴"));
			}
		});
		window.addEventListener('resize',function() {
		  MapChart.resize();
		});
		});
	},
	//组装数据
	initLoadCharts:function(chartsId,option) {
		var bcCharts = echarts.init(chartsId);
		bcCharts.setOption(option);
	},
	initData:function() {
		//班车客运量变化
			echartsBuild.initLoadCharts(document.getElementById("bcBus"),echartsBuild.echartsLine(
			['01-12', '01-13', '01-14', '01-15', '01-16', '01-17',"01-18"],
			"班车客运量变化",
			"客运量",
			[1118, 1175, 671, 551, 400, 677, 899, 131, 155, 467, 148]
			));
			//包车客运量变化
			echartsBuild.initLoadCharts(document.getElementById("baocBus"),echartsBuild.echartsLine(
			['01-12', '01-13', '01-14', '01-15', '01-16', '01-17',"01-18"],
			"包车客运量变化",
			"客运量",
			[1118, 1175, 671, 551, 400, 677, 899, 131, 155, 467, 148]
			));
			//公交客运量变化
			echartsBuild.initLoadCharts(document.getElementById("gjBus"),echartsBuild.echartsLine(
			['01-12', '01-13', '01-14', '01-15', '01-16', '01-17',"01-18"],
			"公交客运量变化",
			"客运量",
			[1118, 1175, 671, 551, 400, 677, 899, 131, 155, 467, 148]
			));
		//特色客运
			//定制客运
			echartsBuild.initLoadCharts(document.getElementById("dzBus"),echartsBuild.echartsColumnar(
			"定制客运",
			['定制线路', '定制车辆数', '当日发车班次'],
			[18203, 23489, 29034],
			{
						top:20,
						height:90,
						left:10,
						containLabel: true
			}
			));
			//掌上包车
			echartsBuild.initLoadCharts(document.getElementById("zsBus"),echartsBuild.echartsColumnar(
			"掌上包车",
			['当日包车订单数', '当日载客数'],
			[18203, 23489],
			{
						top:30,
						height:70,
						left:10,
						containLabel: true
			}
			));
			//数字打非
			echartsBuild.initLoadCharts(document.getElementById("szBus"),echartsBuild.echartsColumnar(
			"数字打非",
			['落实布控车辆数', '综合预测车辆数',"系统预测车辆数","触网预警车辆数"],
			[183, 489,234,56],
			{
						top:50,
						height:120,
						left:10,
						containLabel: true
			}
			));
			//共同富裕
			echartsBuild.initLoadCharts(document.getElementById("gtBus"),echartsBuild.echartsColumnar(
			"",
			['城乡公交平均票价','行政村公交通达率'],
			[8, 80],
			{
						top:30,
						height:70,
						left:10,
						containLabel: true
			}
			));
		//行业规模
			//客运企业数量
			//客运车辆数量
			//客运驾驶员数量
		echartsBuild.initLoadCharts(document.getElementById("hyBus"),
		echartsBuild.echartsPie([{
			data:[
			  {
				name: '班车',
				value: [3089,"家"]
			  },
			  {
				name: '包车',
				value: [4867,"家"]
			  },
			  {
				name: '公交',
				value: [2845,"家"]
			  }
			],
			titleName:"客运企业数量"
		},
		{
			data:[
			  {
				name: '班车',
				value: [1704,"辆"]
			  },
			  {
				name: '包车',
				value: [1685,"辆"]
			  },
			  {
				name: '公交',
				value: [6486,"辆"]
			  }
			],
			titleName:"客运车辆数量"
		},
		{
			data:[
			  {
				name: '班车',
				value: [1170,"人"]
			  },
			  {
				name: '包车',
				value: [1168,"人"]
			  },
			  {
				name: '公交',
				value: [4148,"人"]
			  }
			],
			titleName:"客运驾驶员数量"
		}]));
		
		//运行动态
			//企业运营车辆数TOP5
		echartsBuild.listTop($("#qyTop"),
				[["1","杭州汽运公司","230"],
				  ["2","绍兴汽运公司","200"],
				  ["3","宁波汽运公司","180"],
				  ["4","温州汽运公司","150"],
				  ["5","新昌县白云旅行社","110"],
				]);
		//客运站人流量TOP5
		echartsBuild.listTop($("#kyTop"),
				[["1","九堡客运中心","杭州","1130"],
				  ["2","杭州汽车南站","杭州","1020"],
				  ["3","宁波港客运站","宁波","890"],
				  ["4","双屿客运中心","温州","765"],
				  ["5","杭州汽车西站","杭州","734"],
				]);
		//城市销售收入TOP5
		echartsBuild.listTop($("#cityTop"),
				[["1","杭州","800"],
				  ["2","宁波","750"],
				  ["3","温州","600"],
				  ["4","金华","557"],
				  ["5","衢州","320"],
				]);
	},
	initShaoXingData:function() {
		//班车客运量变化
			echartsBuild.initLoadCharts(document.getElementById("bcBus"),echartsBuild.echartsLine(
			['01-12', '01-13', '01-14', '01-15', '01-16', '01-17',"01-18"],
			"班车客运量变化",
			"客运量",
			[718, 475, 271, 351, 200, 377, 499, 131, 155, 167, 148]
			));
			//包车客运量变化
			echartsBuild.initLoadCharts(document.getElementById("baocBus"),echartsBuild.echartsLine(
			['01-12', '01-13', '01-14', '01-15', '01-16', '01-17',"01-18"],
			"包车客运量变化",
			"客运量",
			[518, 1175, 171, 551, 400, 677, 899, 131, 155, 467, 148]
			));
			//公交客运量变化
			echartsBuild.initLoadCharts(document.getElementById("gjBus"),echartsBuild.echartsLine(
			['01-12', '01-13', '01-14', '01-15', '01-16', '01-17',"01-18"],
			"公交客运量变化",
			"客运量",
			[8118, 1175, 171, 451, 400, 677, 899, 131, 155, 467, 148]
			));
		//特色客运
			//定制客运
			echartsBuild.initLoadCharts(document.getElementById("dzBus"),echartsBuild.echartsColumnar(
			"定制客运",
			['定制线路', '定制车辆数', '当日发车班次'],
			[8203, 3489, 9034],
			{
						top:20,
						height:90,
						left:10,
						containLabel: true
			}
			));
			//掌上包车
			echartsBuild.initLoadCharts(document.getElementById("zsBus"),echartsBuild.echartsColumnar(
			"掌上包车",
			['当日包车订单数', '当日载客数'],
			[7203, 6489],
			{
						top:20,
						height:70,
						left:10,
						containLabel: true
			}
			));
			//数字打非
			echartsBuild.initLoadCharts(document.getElementById("szBus"),echartsBuild.echartsColumnar(
			"数字打非",
			['落实布控车辆数', '综合预测车辆数',"系统预测车辆数","触网预警车辆数"],
			[283, 389,134,36],
			{
						top:20,
						height:120,
						left:10,
						containLabel: true
			}
			));
			//共同富裕
			echartsBuild.initLoadCharts(document.getElementById("gtBus"),echartsBuild.echartsColumnar(
			"",
			['城乡公交平均票价','行政村公交通达率'],
			[7, 89],
			{
						top:20,
						height:70,
						left:10,
						containLabel: true
			}
			));
		//行业规模
			//客运企业数量
			//客运车辆数量
			//客运驾驶员数量
		echartsBuild.initLoadCharts(document.getElementById("hyBus"),
		echartsBuild.echartsPie([{
			data:[
			  {
				name: '班车',
				value: [100,"家"]
			  },
			  {
				name: '包车',
				value: [289,"家"]
			  },
			  {
				name: '公交',
				value: [180,"家"]
			  }
			],
			titleName:"客运企业数量"
		},
		{
			data:[
			  {
				name: '班车',
				value: [409,"辆"]
			  },
			  {
				name: '包车',
				value: [386,"辆"]
			  },
			  {
				name: '公交',
				value: [187,"辆"]
			  }
			],
			titleName:"客运车辆数量"
		},
		{
			data:[
			  {
				name: '班车',
				value: [407,"人"]
			  },
			  {
				name: '包车',
				value: [386,"人"]
			  },
			  {
				name: '公交',
				value: [365,"人"]
			  }
			],
			titleName:"客运驾驶员数量"
		}]));
		
		//运行动态
			//企业运营车辆数TOP5
		echartsBuild.listTop($("#qyTop"),
				[
				  ["1","绍兴汽运公司","200"],
				  ["2","绍兴市公共交通集团","170"],
				  ["3","绍兴客运中心","134"],
				  ["4","绍兴市冠荣旅游客运","112"],
				  ["5","绍兴新旅旅游客运公司","99"],
				]);
		//客运站人流量TOP5
		echartsBuild.listTop($("#kyTop"),
				[["1","绍兴客运站","绍兴","830"],
				  ["2","绍兴汽车西站","绍兴","720"],
				  ["3","绍兴汽车东站","绍兴","590"],
				  ["4","绍兴汽车南站","绍兴","365"],
				  ["5","嵊州汽车站","绍兴","234"],
				]);
		//城市销售收入TOP5
		echartsBuild.listTop($("#cityTop"),
				[["1","柯桥区","600"],
				  ["2","越城区","450"],
				  ["3","上虞区","300"],
				  ["4","诸暨市","257"],
				  ["5","嵊州市","120"]
				]);
	}
}

var cityData = [{"name":"柯桥区",value:25},
{"name":"越城区",value:25},
{"name":"上虞区",value:25},
{"name":"诸暨市",value:25},
{"name":"嵊州市",value:25},
{"name":"新昌县",value:25}
];
function make_city(cityname,MapChart){
	var option =  {
		"title": [
			{
				"textStyle": {
					"color": "#000", 
					"fontSize": 18
				}, 
				"subtext": "", 
				"text": "", 
				"top": "auto", 
				"subtextStyle": {
					"color": "#aaa", 
					"fontSize": 12
				}, 
				"left": "auto"
			}
		], 
		"legend": [
			{
				"selectedMode": "multiple",
				"top": "top",
				"orient": "horizontal",
				"data": [
					""
				],
				"left": "center",
				"show": true
			}
		],
		"backgroundColor": "rgba(255,255,255,0)",
		"series": [
			{
				"mapType": cityname,
				zoom:1.4,
				"data": cityData,
				"name": "",
				"symbol": "circle",
				"type": "map",
				"roam": true,
				itemStyle: {
				    normal: {
				        areaColor: '#142957',
				        borderColor: '#0692a4',
				    },
				    emphasis: {
				        areaColor: '#0b1c2d',
				    }
				},
				label: {
					color: '#D4EEFF',
				    normal: {
				        formatter: '{city|{b}}',
				        position: 'right',
				        show: true,
						rich:{
							city:{
								color:"#D4EEFF"
							}
						}
				    },
				  emphasis: {
					  show: true
				  }
				},
				markPoint:{
					symbol:function(value,params) {
						if(params.name == "一级站点") {
							return "image://images/cityBus/一级客运站点.png";
						}else if(params.name == "二级站点") {
							return "image://images/cityBus/二级客运站点.png";
						}else if(params.name == "三级站点") {
							return "image://images/cityBus/三级客运站点.png";
						}else if(params.name == "便携客运站点") {
							return "image://images/cityBus/便携客运站点.png";
						}else if(params.name == "招手站"){
							return "image://images/cityBus/招呼站.png";
						}
					},
					data:[{"name":"一级站点","coord":[120.64691822315731,30.18344328732051]},{"name":"一级站点","coord":[120.76843113697011,30.14201843033888]},{"name":"一级站点","coord":[120.66410186753488,30.079420868677747]},{"name":"一级站点","coord":[120.34129483387062,29.898992602713303]},{"name":"一级站点","coord":[120.6186879502515,29.65228456557833]},{"name":"二级站点","coord":[120.88626184127358,29.43043144263232]},{"name":"二级站点","coord":[121.0605530913889,29.47369740436869]},{"name":"二级站点","coord":[120.90958250150028,29.64031738467258]},{"name":"二级站点","coord":[120.38302654164488,29.654125670333126]},{"name":"二级站点","coord":[120.61255093440249,29.80969902210863]},{"name":"二级站点","coord":[120.70706097847909,29.970795688148307]},{"name":"三级站点","coord":[120.91449211417971,29.92476806927983]},{"name":"三级站点","coord":[121.0360050279925,29.822586755391804]},{"name":"三级站点","coord":[120.64078120730849,30.03615490694155]},{"name":"三级站点","coord":[120.44316929696649,30.0103794403752]},{"name":"三级站点","coord":[120.35970588141831,29.850203326712894]},{"name":"三级站点","coord":[120.83962052082032,29.654125670333173]},{"name":"便携客运站点","coord":[120.82611908595234,29.40465597606608]},{"name":"便携客运站点","coord":[121.11701363720114,29.41202039508504]},{"name":"便携客运站点","coord":[120.94517719342548,29.645840698936915]},{"name":"便携客运站点","coord":[121.00163773923764,29.951464088223606]},{"name":"便携客运站点","coord":[120.36707030043753,29.703835498711186]},{"name":"便携客运站点","coord":[120.37566212262631,30.07389755441376]},{"name":"招手站","coord":[120.64569081998806,30.072056449659023]},{"name":"招手站","coord":[120.58800287100635,29.954225745355753]},{"name":"招手站","coord":[120.39898278285314,30.020505516526363]},{"name":"招手站","coord":[120.84207532716036,29.963431269129448]},{"name":"招手站","coord":[120.37811692896618,29.63939683229542]},{"name":"招手站","coord":[120.6260523692712,29.641237937050214]},{"name":"招手站","coord":[121.02864060897424,29.40557652844362]}],
					symbolSize:25
				}
			}
		]
	};
	MapChart.setOption(option);
	
	var num = 0;
	var datazuobiao = [];
	MapChart.on('click', function (params) {
		// let componentType = params.componentType;   // geo是地图图层
		// console.log(componentType);
		// if (componentType == "series") {
		// 	let offsetX = params.event.offsetX;
		// 	let offsetY = params.event.offsetY;
		// 	let zuobiao = MapChart.convertFromPixel({seriesIndex:0}, [offsetX, offsetY]); // 转换成坐标
		// 	num++;
		// 	name = "";
		// 	if(num < 6){
		// 		name = "一级站点";
		// 	}else if(num <12) {
		// 		name = "二级站点";
		// 	}else if(num < 18) {
		// 		name = "三级站点";
		// 	}else if(num < 24) {
		// 		name = "便携客运站点";
		// 	}else {
		// 		name = "招手站";
		// 	}
		// 	console.log(zuobiao);
		// 	datazuobiao.push({name:name,coord:zuobiao});
		// }
		
		// console.log(JSON.stringify(datazuobiao));
		//新昌县
		if(params.name.indexOf("新昌县") != -1) {
			console.log("新昌县切换...");
			window.open("https://datav.aliyuncs.com/share/489d3e1eccbcad035d15febbd50c672c?whatever=true");
		}
	});
	
	
}